Select data that meet criteria from a table adding it to a combobox in userform VBA Excel 您所在的位置:网站首页 combobox value Select data that meet criteria from a table adding it to a combobox in userform VBA Excel

Select data that meet criteria from a table adding it to a combobox in userform VBA Excel

2023-03-26 08:07| 来源: 网络整理| 查看: 265

Please be patient with me; I'm new to coding and am well over my head. I have an excel table with data. I want to use VBA to choose values (numbers) from the table's Active Accessions, first column, that are in the same row as names in the second column. The names correspond to those in a combination box (cmbxLatinName). The list of chosen numbers from column 1 should then be added as a result of all of this into a separate comboxbox (cmbxSourceAcc). This current code, which I spent hours searching for to understand and utilise, sounds nice, but I can't get the Datarw right; I can't 'dim' it. I was going to write the results into the third column of the table since I knew how to pull them into the combobox even though there is a way to get directly into the combo box that is too hard for me. I'm sure my project and code are ugly, but I'm learning and they do provide the outcomes when I can get them to function.

'Match source accession to its sub-accession Public Function GetSourceAcc() Dim Tbl As ListObject Dim r As Long Dim Datarw As Set Tbl = Sheet5.ListObjects("Active_Accessions") r = 1 For Each Datarw In Tbl.ListRows If Datarw.ListColumns(2).DataBodyRange = Me.cmbxLatinName.Value Then Tbl.ListColumns(3).Offset(r, 0) = Tbl.ListColumns(1).Value r = r + 1 End If Next GetSourceAcc = Sheet5.ListObjects("Active_Accessions").ListColumns(3).DataBodyRange.Value Let Me.cmbxSourceAcc.List = GetSourceAcc Me.cmbxSourceAcc.ListIndex = 0 End Function

The line Dim Datarw As... I can't figure out the correct way to dim it so it breaks/debugs too for or if depending on how I dim it.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有